home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr23 / chansw53.zip / CHAIN3.CPP < prev    next >
C/C++ Source or Header  |  1993-05-24  |  3KB  |  115 lines

  1. // FILE: CHAIN3.CPP
  2. // MODULE: FUNCTIONS
  3. // PROGRAM: CHAINSAW 
  4.  
  5. // Public Domain, 5/24/93, Ted Davis
  6.  
  7. #include "chainsaw.hpp"
  8.  
  9.  
  10. void Barf(void)
  11. // The abort function.
  12. {
  13.     Output(BarfMessage);
  14.  
  15.     setcbrk(cbreak); exit(1);
  16. }
  17.  
  18. int CtrlBreakRoutine(void)
  19. // This is the code that runs when Ctrl + Break or Ctrl + C is pressed.
  20. {
  21.     // This message is not suppressable by command tail switches.
  22.     cerr << "\n\n CHAINSAW ABORTED by user!\n";
  23.     cerr << "Directory " << InitialDirectory;
  24.     cerr << "\nand its subdirectories are probably damaged.\n\n";
  25.     setcbrk(cbreak);    // Restores break setting to the original value.
  26.     exit(3);
  27.     return(0);
  28. }
  29.  
  30. char *Emessage(void)
  31. // Returns a pointer to an error message string built from the immediate
  32. // text and the message string supplied by _strerror(), which explains the
  33. // last error that set errno.  Originally it was longer than this.
  34. {
  35.     return(_strerror("*** Error"));
  36. }
  37.  
  38. void Encrypt(char *key, char *string, int length)
  39. // This is intentionally uncommented.
  40. {
  41. int i;
  42.     for(i = 0; i < length; i++)
  43.     {
  44.         string[i] = string[i] ^ key[i];
  45.     }
  46. }
  47.  
  48. void InsertVersion(char * Vlocation)
  49. // Inserts the version number into a string at the given location.
  50. {
  51.     strncpy(Vlocation, VersionNumber, 5);
  52.     // VersionNumber is 6 characters long, so copying 5 characters does not
  53.     // terminate the string in work, but merely inserts the version number.
  54. }
  55.  
  56. #define CarryFlagBit 0x0001
  57. #define NetDriveBit 0x1000
  58. int NetworkDriveQuery(int DriveLetter)
  59. // Determines if the target drive is valid and local (returns 0), valid and
  60. // remote (1), no network installed or invalid drive (-1).
  61. // This function uses DOS interrupt 0x21, function 0x4409  Since the
  62. // compiler has a tendency to trash flags on return from an interrupt, this
  63. // is largely in assembly language.
  64. {
  65.     // Save the registers to be used (and flags).
  66.     asm{
  67.         push    bx
  68.         push    cx
  69.         push    dx
  70.         push    bp
  71.         pushf
  72.     }
  73.     // Set up the drive number in BX.
  74.     _BX = DriveLetter - 'A' + 1;
  75.     // Drive 0 is the default, 1 is A, etc.
  76.  
  77.     // Note: jc comes out jb in the compiled code - therefore the somewhat
  78.     // unusual way of testing the carry flag.
  79.     asm{
  80.         mov        ax,4409h
  81.         int     21h
  82.         pushf
  83.         pop        ax
  84.         and        ax,CarryFlagBit
  85.         cmp        ax,CarryFlagBit
  86.         je        err
  87.         and        dx,NetDriveBit
  88.         cmp        dx,NetDriveBit
  89.         jne        ok
  90.         mov     ax,1
  91.         jmp     done
  92.     }
  93.     // Return 0 if valid and local.
  94.     ok:
  95.     asm{
  96.         xor        ax,ax
  97.         jmp        done
  98.     }
  99.     // Return -1 if invalid drive.
  100.     err:
  101.     asm    mov        ax,-1
  102.     done:
  103.     // Restore the registers used, except AX, which is the return value.
  104.     asm{
  105.         popf
  106.         pop        bp
  107.         pop        dx
  108.         pop        cx
  109.         pop        bx
  110.     }
  111.     return(_AX); // +1, 0, or -1 only.
  112. }
  113. #undef CarryFlagBit
  114. #undef NetDriveBit
  115.